/**********************************************************
 * Validator.java.java
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 11:07:50 AM by Ashutosh
 * Revision: <svn revision #>
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.util;

import org.apache.log4j.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * The Class Validator.
 */
public class Validator {

	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(Validator.class);

	/**
	 * Checks if is mail address.
	 *
	 * @param email the email
	 *
	 * @return true, if is mail address
	 */
	public static boolean isMailAddress(String email) {
		if (logger.isDebugEnabled()) {
			logger.debug("isMailAddress(String) - start"); //$NON-NLS-1$
		}

		//Set the email pattern string
	      Pattern p = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

	      //Match the given string with the pattern
	      Matcher m = p.matcher(email);

	      //check whether match is found
		boolean returnboolean = m.matches();
		if (logger.isDebugEnabled()) {
			logger.debug("isMailAddress(String) - end"); //$NON-NLS-1$
		}
	      return returnboolean;
	}
}